package com.example.demo.nosql.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.redisx.RedisClient;
import org.noear.solon.annotation.*;

/**
 * @author airhead
 */
@Controller
@Mapping("/redis")
@Api("redis")
public class RedisController {
  @Inject private RedisClient redisClient;

  @Mapping
  @Get
  @ApiOperation("获取key的值")
  public String get(String key) {
    return redisClient.openAndGet(session -> session.key(key).get());
  }

  @Mapping
  @Post
  @ApiOperation("设置key的值")
  public Boolean set(String key, String value) {
    redisClient.open(
        session -> {
          session.key(key).set(value);
        });

    return true;
  }
}
